package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.service.ITravelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private ITravelService travelService;
    @Autowired
    private IStrategyService strategyService;

    @GetMapping("")
    public Object search(String keyword, String type, HttpSession session) {
        HashMap<String, List> map = new HashMap<>();
        if ("travels".equals(type)||"all".equals(type)) {
            List<Map<String, Object>> travels = travelService.selectTravelByKeyword(keyword);
            map.put("travels", travels);
        }
        if ("strategies".equals(type)||"all".equals(type)) {
            List<Map<String, Object>> strategies = strategyService.selectStrategyByKeyword(keyword);
            map.put("strategies", strategies);
        }

        return map;
    }
}
